package coreutil

import (
	"core/mongo"
	"go.mongodb.org/mongo-driver/mongo/gridfs"
	"go.mongodb.org/mongo-driver/mongo/options"
)

var (
	MongoUtil = mongo.Db
)

func GetGridfsBucket(collName string) *gridfs.Bucket {
	var bucket *gridfs.Bucket
	// 使用默认文件集合名称
	if collName == "" || collName == options.DefaultName {
		bucket, _ = gridfs.NewBucket(MongoUtil)
	} else {
		// 使用传入的文件集合名称
		bucketOptions := options.GridFSBucket().SetName(collName)
		bucket, _ = gridfs.NewBucket(MongoUtil, bucketOptions)
	}
	return bucket
}
